package com.couldtest.utils;

import com.netflix.zuul.context.RequestContext;
import org.springframework.stereotype.Component;

@Component
public class FilterUtils {
    public   final  String PRE = "pre";

    private static  final  String CORRELATION_ID = "tmx-correlation-ID";

    public String getCorrelationId(){
        RequestContext ctx = RequestContext.getCurrentContext();
        if(ctx.getRequest().getHeader(CORRELATION_ID) != null){
            return ctx.getRequest().getHeader(CORRELATION_ID);
        }else {
            return ctx.getZuulRequestHeaders().get(CORRELATION_ID);
        }
    }

    /**zuul不允许直接添加或者修改传入请求中的HTTP请求首部
     * */
    public void setCorrelationId(String correlationId){
        RequestContext ctx = RequestContext.getCurrentContext();
        ctx.addZuulRequestHeader(CORRELATION_ID,correlationId);

    }
}
